home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9436 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: DESPERATE with Borland C++ 4.5 compiler
  5. Date: 1 Mar 1996 18:15:54 GMT
  6. Organization: Borland International
  7. Message-ID: <4h7esq$6v@druid.borland.com>
  8. References: <4h08er$op5@news.cs.tu-berlin.de>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4h08er$op5@news.cs.tu-berlin.de>, wolfro@cs.tu-berlin.de says...
  15. >
  16. >Ali Lattunen <Ali.Lattunen@vtt.fi> writes:
  17. >> 
  18. >> Still the same problem:
  19. >> 
  20. >> Linker recognizes only one instance of template class non-inline member 
  21. >> functions. If I have two template class instancies of different user
  22. >> defined type as my class members, e.g.,
  23. >> 
  24. >> class MyClass {
  25. >> ..
  26. >>  TemplateClass<X> XMember;
  27. >>  TemplateClass<Y> YMember;
  28. >> };
  29. >> 
  30. >> member functions TemplateClass<Y>::XXX that are not inline are not 
  31. >> recognized by the linker.
  32. >> 
  33. >> If I declare them inline, the linker works fine even if the compiler 
  34. >> warns that functions cannot be expanded inline due to while-statements 
  35. >> inside the function body.
  36. >> 
  37. >> How is this done right? 
  38. >> How can I avoid using inline functions here?
  39. >> 
  40. >> Does Borland have any online user information service?
  41. >> 
  42. >
  43. >Well, I've had the same problem. As far as I understand this mess there is a 
  44. bug 
  45. >in the compiler. When you create a template class and then instantiate it the 
  46. compiler 
  47. >has to generate the code for the member functions. Certainly the code has to 
  48. be placed 
  49. >in some module. The "Smart Template" option lets the compiler select the 
  50. module for the 
  51. >code. Probably you can guess... this stupid thing doesn't generate the code 
  52. at all ( the 
  53. >inline functions run since no code needs to be generated - they are inline, 
  54. aren't they ).
  55. >The only solution I have found is to compile one module with the -Jgd ( 
  56. Global Templates ) 
  57. >option and the others with the -Jgx ( External Templates ) option. A nice 
  58. side effect is 
  59. >that you cannot use precompiled headers if these options are specified in the 
  60. makefile or 
  61. >in the project. So you have to use #pragma's after the #include's and 
  62. instantiate ALL of 
  63. >your template classes in ONE module or cast all those #pragma's all over your 
  64. source... 
  65. >it's really a mess but it works.
  66. >By the way, there is one thing I don't understand. The first time I 
  67. encountered this problem 
  68. >I tried to compile some of the example files which deal with template and 
  69. they didn't run 
  70. >either. Now tell me, am I doing something wrong or don't these guys test 
  71. their examples at all?
  72.  
  73.     Don't mess with the -Jg switches. They'll get you into trouble. The 
  74. template model that every compiler today except cfront supports is that the 
  75. compiler has to see the entire template definition at the point where it is 
  76. used. That includes non-inline member functions. The easiest way to do this is 
  77. to put everything in the header file.
  78.  
  79.